package com.t4.process.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.t4.common.result.Result;
import com.t4.model.process.ProcessType;
import com.t4.process.service.ProcessTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "审批类型管理")
@RestController
@RequestMapping("/admin/process/processType")
public class ProcessTypeController {

    @Resource
    private ProcessTypeService processTypeService;

    @ApiOperation(value = "分页查询审批类型")
    @GetMapping("{current}/{size}")
    public Result pageQuery(@PathVariable Long current,
                            @PathVariable Long size){
        Page<ProcessType> pageParam = new Page<>(current, size);
        processTypeService.page(pageParam);
        return Result.success(pageParam);
    }

    @ApiOperation(value = "根据id获取审批类型")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        ProcessType processType = processTypeService.getById(id);
        return Result.success(processType);
    }

    @ApiOperation(value = "新增审批类型")
    @PostMapping("save")
    public Result save(@RequestBody ProcessType processType){
        boolean is_success = processTypeService.save(processType);
        if(is_success){
            return Result.success();
        }else{
            return Result.fail();
        }
    }

    @ApiOperation(value = "修改审批类型")
    @PutMapping("update")
    public Result updateById(@RequestBody ProcessType processType){
        boolean is_success = processTypeService.updateById(processType);
        if(is_success){
            return Result.success();
        }else{
            return Result.fail();
        }
    }


    @ApiOperation(value = "删除审批类型")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        boolean is_success = processTypeService.removeById(id);
        if(is_success){
            return Result.success();
        }else{
            return Result.fail();
        }
    }

    @ApiOperation(value = "获取全部审批分类")
    @GetMapping("findAll")
    public Result findAll(){
        List<ProcessType> list = processTypeService.list();
        return Result.success(list);
    }

}
